<%@ page language="java"  pageEncoding="utf-8" import="java.util.*" import="com.yinhai.model.FileInfo"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
  <head>
   <title>小菜毛毛文件系统</title>
	<link rel="stylesheet" type="text/css" href="../CSS/BasicStyle.css">
	<style type="text/css">
body{margin:0px;}
body,td,th{font-size: 12px;}
fieldset{padding:10px;}
img
{
border: 0;
vertical-align:middle;
}
table
{
width:100%;
border:1px solid #bbd7e6;
}
th
{
border-bottom:1px solid #bbd7e6;
background-color:#E1ECFE;
}
.I
{
width:16px;
height:16px;
}
.H
{
  filter:alpha(opacity=50)
}

.r
{
text-align:right;
}
</style>

  <script type="text/javascript">
  //此方法用于弹出错误信息
  function showError()
  {
    //var errorMSG=document.getElementById("error").value;
   // if(errorMSG!="")
   //  {
   //  alert(errorMSG);
   //  }
  }
  //此方法用于选择常用路径后的跳转
  function goDir()
  {
  var s=document.getElementById("pmenu").value;
  window.location.href=s;
  }
  //此方法用于手工输入，并跳入相关路径
  function findFiles()
  {
  //var s=document.getElementById("file").value;
  form1.action="../servlet/FileDeal";
  mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
  mt=document.createElement("<input type='hidden' name='mt' id='mt' value='find'/>");
  form1.insertAdjacentElement("beforeEnd",mainGo);
  form1.insertAdjacentElement("beforeEnd",mt);
  form1.submit();
  }
  //此方法用于删除文件或者目录
  function delFile()
  {
    var isDelete=confirm("是否确认删除");
    if(isDelete==true)
    {
    var checks=document.getElementsByName("ps");
    for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='delete'/>");
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
    }
    
  }
  
  //此方法用于新建目录
  function createDir()
  {
    var dirName=prompt("请输入需要创建的目录名称","");
    if(dirName!=null&&dirName!="")
    {
       form1.action="../servlet/FileDeal";
       mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
       mt=document.createElement("<input type='hidden' name='mt' id='mt' value='createDir'/>");
       dirname=document.createElement('input');
       dirname.type='hidden';
       dirname.id='dirname';
       dirname.name='dirname';
       dirname.value=dirName;
       form1.insertAdjacentElement("beforeEnd",mainGo);
       form1.insertAdjacentElement("beforeEnd",mt);
       form1.insertAdjacentElement("beforeEnd",dirname);
       form1.submit();
    }
  }
  //此方法用于剪切
  function cutFile()
  {
     var checks=document.getElementsByName("ps");
     for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='cut'/>");
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
  }
    //此方法用于复制
  function copyFile()
  {
     var checks=document.getElementsByName("ps");
     for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='copy'/>");
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
  }
  //此方法用于黏贴被剪切或者被复制的文件或目录
  function pasteFile()
  {
  	form1.action="../servlet/FileDeal";
  	mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
  	mt=document.createElement("<input type='hidden' name='mt' id='mt' value='parse'/>");
 	form1.insertAdjacentElement("beforeEnd",mainGo);
  	form1.insertAdjacentElement("beforeEnd",mt);
 	form1.submit();
  }
  //此方法用于文件以及目录的压缩
  function zipFile()
  {
     var checks=document.getElementsByName("ps");
     for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='zip'/>");
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
  }
  //此方法用于文件解压
  function unzipFile()
  {
     var checks=document.getElementsByName("ps");
     for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='unzip'/>");
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
  
  }
  //此方法用于重命名
  function reNameFile()
  {
   var dirName=prompt("请输入重命名名称","");
   if(dirName!=null&&dirName!="")
   {
     var checks=document.getElementsByName("ps");
     for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='reName'/>");
    dirname=document.createElement('input');
    dirname.type='hidden';
    dirname.id='dirname';
    dirname.name='dirname';
    dirname.value=dirName;
    form1.insertAdjacentElement("beforeEnd",dirname);
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
   }
  }
    //此方法用于下载
  function downFile()
  {
 
     var checks=document.getElementsByName("ps");
     for(var i=0;i<checks.length;i++)
    {
     if(checks[i].checked)
      {
      fPath=document.createElement("<input type='hidden' name='f' />");
      fPath.value=checks[i].value;
      form1.insertAdjacentElement("beforeEnd",fPath);
      }
    }
    mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='down'/>");
    
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.submit();
  
  }
  //此方法用于上传
  function upLoad()
  {
  	mainGo=document.createElement("<input type='hidden' name='mainGo' id='mainGo' value='fileMain'/>");
    mt=document.createElement("<input type='hidden' name='mt' id='mt' value='upLoad'/>");
    form1.insertAdjacentElement("beforeEnd",mainGo);
    form1.insertAdjacentElement("beforeEnd",mt);
    form1.action="../servlet/FileDeal";
    form1.enctype="multipart/form-data";
    form1.method='post';
    form1.encoding="multipart/form-data";
    form1.submit();
  }
  //此方法用于checkbox全选
  function checkAll(obj,cName)
  {
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++)
    {
    checkboxs[i].checked = obj.checked;
    }
    showButton();
  
  }
  //此方法用于确定按钮的状态
  function showButton()
  {
     var checkbox=document.getElementsByName("ps");
     var isUse="disabled";
     for(var i=0;i<checkbox.length;i++)
     {
     if(checkbox[i].checked)
      {
        isUse="";
        break;
      }
     }
     if(isUse=="disabled")
      {
       if(document.getElementById("mainPs").checked)
       {
        isUse="";
       } 
      }
     var buttons=new Array("cut","copy","del","ren","unzip","zip","down","kill","start","stop","restart");
     for(var i=0;i<buttons.length;i++)
     {
      var obj=document.getElementById(buttons[i]);
      obj.disabled=isUse;
     }
  }
  </script>
  </head>
  
  <body onload="showError();">
  <form action="#" name="form1" id="form1" method="post">
<input type='hidden' name='error' id='error' value="${error }" />
<input type="text" id="file" name="file" value="${pathDirectory}" onfocus="select();" style="position:absolute; width:400px; top:1px;">
<select id="pmenu" style="position:absolute; width:400px; top:1px; clip:rect(0 400 20 381)" onchange="goDir();">
<c:forEach items="${DirGudie}" var="ss">
	<option value="../servlet/FileDeal?mainGo=fileMain&mt=find&file=${ss.filePath}">"${ss.fileName}"</option>
</c:forEach>
</select>
<span style="width:400px">　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　</span>
<script type=""></script>
<input type="button" id="go" value="转到" onclick="findFiles();" />
<input type="button" id="cut" value="剪切" onclick="cutFile();" disabled="disabled"/>
<input type="button" id="copy" value="复制" onclick="copyFile();" disabled="disabled"/>
<input type="button" <%if(session.getAttribute("file.cut")==null&&session.getAttribute("file.copy")==null)out.print(" disabled ");%> value="粘贴" onclick="pasteFile();"/>
<input type="button" disabled="disabled" id="del" value="删除" onclick="delFile();"/>
<input type="button" disabled="disabled" id="ren" value="改名" onclick="reNameFile();"/>
<input type="button" disabled="disabled" id="unzip" value="解压" onclick="unzipFile();"/>
<input type="button" disabled="disabled" id="zip" value="压缩" onclick="zipFile();"/>
<input type="button" disabled="disabled" id="down" value="下载" onclick="downFile();"/>
<span><input type="file"  name='upload' style="position:absolute;width:72px;filter:alpha(opacity=0)" onchange="upLoad();"><input type="button" value="上传文件"></span>
<input type="button" id="mkdir" value="创建" onclick="createDir();"/>
<table cellspacing="1">
<tr>
  <th width="1"><input type="checkbox" onclick="checkAll(this,'ps')" id="mainPs"/></th>
  <th><a href="javascript:o(1)">名称</a></th>
  <th align="right"><a href="">大小</a></th>
  <th>类型</th>
  <th><a href="javascript:o(4)">日期</a></th>
  <th>属性</th>
</tr>
<%--
<%
ArrayList al=(ArrayList)request.getAttribute("sss");
out.print(al.size());
FileInfo fi=null;
for(int i=0;i<al.size();i++){
     fi=(FileInfo)al.get(i);
 %>
<tr onmouseover="bgColor='#EAF1F9';" onmouseout="bgColor='';" >
  <td><input type='checkbox' name='ps' onclick='s(this)' value="pc"/></td> 
  <td></td>
  <td><%=fi.getFileName() %></td>
  <td class="r"></td>
  <td></td>
  <td></td>
</tr>
<%
}
 %>
--%>

<c:forEach items="${sss}" var="iss">
<tr onmouseover="bgColor='#EAF1F9';" onmouseout="bgColor='';" >
  <td><input type='checkbox' name='ps' onclick='showButton();' value="${iss.filePath}" id="ps"/><br></td> 
  <td>
  <c:choose>
   <c:when test="${iss.isFile!=null && iss.isFile!=''}">
    <a href="../servlet/FileDeal?mainGo=fileMain&mt=downFile&file=${iss.filePath}"> 
    <img src="../servlet/ShowImage?file=${iss.filePath}" class="I"/>
    ${iss.fileName}
  </a>
   </c:when>
   <c:otherwise>
    <a href="../servlet/FileDeal?mainGo=fileMain&mt=find&file=${iss.filePath}"> 
    <img src="../servlet/ShowImage?file=${iss.filePath}" class="I"/>
    ${iss.fileName}
  </a>
   </c:otherwise>
  
   </c:choose>
  
  <br></td>
  <td class='r'><c:out value="${iss.fileSpace}" /></td>
  <td><c:out value="${iss.fileType}" /></td>
  <td><c:out value="${iss.modifyDate}" /></td>
  <td><c:out value="${iss.property}" /></td>
</tr>
</c:forEach>


</table>
</form>

<table align="center" style="width:600px">
<tr>
<td align="right">Copyright &copy;2010</td>
<td>Powered By <a href="#" target="_blank">小菜毛毛远程管理 Version 1.0</a></td>
</tr>
</table>
  </body>
  
</html>
